package com.baizhi.controller;


import com.baizhi.entity.Student;
import com.baizhi.service.IStudentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haiyu
 * @since 2021-08-26
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private IStudentService ss;

    @GetMapping("selects/{pageNo}/{pageSize}")
    public IPage<Student> selects(@PathVariable ("pageNo") Integer pageNo,@PathVariable("pageSize") Integer pageSize){
        Page<Student> page = new Page<>(pageNo, pageSize);
        page.addOrder(OrderItem.desc("id"));//添加排序的条件降序排列
        return ss.page(page);
    }

    @DeleteMapping("delete/{id}")
    public void delete(@PathVariable("id") Integer id){
        System.out.println("id = " + id);
        ss.removeById(id);
    }
    @GetMapping("selectOne")
    public List<Student> selectOne(){
        List<Student> list = ss.list();
        return  list;
    }
}

